package xxx.demo.web;

import java.util.List;

import xxx.demo.service.Demo;
import xxx.demo.service.DemoQuery;
import com.goldgov.kcloud.core.json.JsonObject;
import com.goldgov.kcloud.core.json.JsonSuccessObject;
import com.goldgov.kcloud.core.json.JsonQueryObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import xxx.demo.service.DemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 演示模块控制器
 * @gen CodeGen v1.1.0
 * @author LiuHG
 */
@RestController
@RequestMapping("/demo")
@Api(tags="演示模块")
public class DemoController {
	
    @Autowired
    private DemoService demoService;
	
	@ApiOperation(value = "新增演示模块")
	@ApiImplicitParams({
	@ApiImplicitParam(name = "demoID", value = "主键", paramType = "query"),
	@ApiImplicitParam(name = "name", value = "姓名", paramType = "query"),
	@ApiImplicitParam(name = "orderNum", value = "排序", paramType = "query"),
	})
	@PostMapping
	public JsonObject<Object> addDemo(@ApiIgnore Demo demo,@RequestHeader(name = "authService.USERID") String userID){
        demoService.addDemo(demo);
        return new JsonSuccessObject<>(demo);
	}
	
	@ApiOperation(value = "更新演示模块")
	@ApiImplicitParams({
	@ApiImplicitParam(name = "demoID", value = "主键", paramType = "query"),
	@ApiImplicitParam(name = "name", value = "姓名", paramType = "query"),
	@ApiImplicitParam(name = "orderNum", value = "排序", paramType = "query"),
	})
	@PutMapping
	public JsonObject<Object>  updateDemo(@ApiIgnore Demo demo){
        demoService.updateDemo(demo);
        return new JsonSuccessObject<>(demo);
	}
	
	@ApiOperation(value = "批量删除演示模块")
	@ApiImplicitParams({ @ApiImplicitParam(name = "ids", value = "演示模块ID", paramType = "query", allowMultiple = true) })
	@DeleteMapping
	public JsonObject<Object> deleteDemo(String[] ids){
        demoService.deleteDemo(ids);
        return JsonSuccessObject.SUCCESS;
	}
	
	@ApiOperation(value = "根据演示模块ID查询演示模块信息")
	@ApiImplicitParams({ @ApiImplicitParam(name = "demoID", value = "演示模块ID", paramType = "path") })
	@GetMapping("/{demoID}")
	public JsonObject<Demo> getDemo(@PathVariable("demoID")String demoID){
        Demo demo = demoService.getDemo(demoID);
        return new JsonSuccessObject<>(demo);
	}
	
	@GetMapping
	@ApiOperation(value = "分页查询演示模块信息")
	@ApiImplicitParams({
	})
	public JsonQueryObject<Demo> listDemo(@ApiIgnore DemoQuery query){
        List<Demo> list = demoService.listDemo(query);
        query.setResultList(list);
        return new JsonQueryObject<>(query);
	}
	
	@PutMapping("/orderByRow")
	@ApiOperation(value = "修改排序到指定的行")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "parentID", value = "父（分组）ID，可不提供", paramType = "query"),
		@ApiImplicitParam(name = "targetRow", value = "移动到的行数", paramType = "query"),
		@ApiImplicitParam(name = "sourceID", value = "要移动的数据主键", paramType = "query")
	})
	public String orderNum(@RequestParam(name="parentID",required=false) String parentID,int targetRow,String sourceID){
		testTableService.moveToRow(parentID,targetRow, sourceID);
		return "SUCCESS";
	}
	
	@PutMapping("/orderByID")
	@ApiOperation(value = "修改排序到指定的记录位置")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "parentID", value = "父（分组）ID，可不提供", paramType = "query"),
		@ApiImplicitParam(name = "targetID", value = "移动到行的记录ID", paramType = "query"),
		@ApiImplicitParam(name = "sourceID", value = "要移动的数据主键", paramType = "query")
	})
	public String orderNum(@RequestParam(name="parentID",required=false) String parentID,String targetID,String sourceID){
		demoService.moveToRow(parentID,targetID, sourceID);
		return "SUCCESS";
	}}